﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;
using System.Data.SqlClient;
using System.Configuration;

namespace Rizmar
{
    public partial class MainForm : Form
    {
        Usuario user;

        public MainForm()
        {
            InitializeComponent();
        }

        public void setUser(Usuario usuario)
        {
            user = usuario;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            bool debug = true;
            if (!debug)
            {
                /* Abre a janela de login */
                LoginForm janela_login = new LoginForm(this);
                janela_login.ShowDialog();

                /* só pode abrir se o login for bem sucedido */
                if (janela_login.DialogResult != DialogResult.OK)
                    Application.Exit();
            }
            else user = new Usuario("Programador", true);
                manutençãoToolStripMenuItem.Enabled = user.getAdmin();
                usuarioStatusLabel.Text = "Logado como " + user.getUsername();
        }


        private void buttonCliente_Click(object sender, EventArgs e)
        {
            if (panelMostrarFormSec.Controls.Count > 0 && panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1] is Form)
                panelMostrarFormSec.Controls.Remove(panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1]);
            this.IsMdiContainer = true;
            ClienteForm novoForm = new ClienteForm();
            novoForm.MdiParent = this;
            panelMostrarFormSec.Controls.Add(novoForm);
            novoForm.Show();
        }

        private void buttonLançamento_Click(object sender, EventArgs e)
        {
            if (panelMostrarFormSec.Controls.Count > 0 && panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1] is Form)
                panelMostrarFormSec.Controls.Remove(panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1]);
            this.IsMdiContainer = true;
            LancamentoForm novoForm = new LancamentoForm();
            novoForm.MdiParent =  this;
            panelMostrarFormSec.Controls.Add(novoForm);
            novoForm.Show();
        }

        private void buttonSacado_Click(object sender, EventArgs e)
        {
            if (panelMostrarFormSec.Controls.Count > 0 && panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1] is Form)
                panelMostrarFormSec.Controls.Remove(panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1]);
            this.IsMdiContainer = true;
            SacadoForm novoForm = new SacadoForm();
            novoForm.MdiParent = this;
            panelMostrarFormSec.Controls.Add(novoForm);
            novoForm.Show();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void buttonTaxas_Click(object sender, EventArgs e)
        {
            TaxasForm janela = new TaxasForm();
            janela.Show();
        }

        private void buttonUsuarios_Click(object sender, EventArgs e)
        {
            UsuarioForm janela = new UsuarioForm();
            janela.Show();
        }

        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MainForm_Load(MainMenuStrip, null);
        }

        private void normalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (panelMostrarFormSec.Controls.Count > 0 && panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1] is Form)
                panelMostrarFormSec.Controls.Remove(panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1]);
            this.IsMdiContainer = true;
            baixaNormal novoForm = new baixaNormal();
            novoForm.MdiParent = this;
            panelMostrarFormSec.Controls.Add(novoForm);
            novoForm.Show();
        }

        private void titulosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioForm1 novo = new RelatorioForm1();
            novo.ShowDialog();
        }

        private void relatório2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioForm novo = new RelatorioForm(this,1);
            novo.ShowDialog();
        }

        private void relatório3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioForm novo = new RelatorioForm(this, 2);
            novo.ShowDialog();
        }

        private void listarBaixaDeHojeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioFormDatas novo = new RelatorioFormDatas(1);
            novo.ShowDialog();
        }

        private void movimentoDoDiaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioForm novo = new RelatorioForm(this, 3);
            novo.ShowDialog();
        }

        private void totalEmprestadoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioFormDatas novo = new RelatorioFormDatas(2);
            novo.ShowDialog();
        }

        private void pesquisaBorderôToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListaBorderoForm janela = new ListaBorderoForm();
            janela.Show();
        }

        private void bBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (panelMostrarFormSec.Controls.Count > 0 && panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1] is Form)
                panelMostrarFormSec.Controls.Remove(panelMostrarFormSec.Controls[panelMostrarFormSec.Controls.Count - 1]);
            this.IsMdiContainer = true;
            baixaBB novoForm = new baixaBB();
            novoForm.MdiParent = this;
            panelMostrarFormSec.Controls.Add(novoForm);
            novoForm.Show();
        }

        private void rendimentosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RelatorioFormDatas novo = new RelatorioFormDatas(3);
            novo.ShowDialog();
        }

    }
}
